package com.yearner.reviewplan.common.util.secure;

import java.io.IOException;

//import java.util.Base64.Decoder;
//import java.util.Base64.Encoder;
import java.util.Base64;
import java.util.Base64.*;
/**
 * Base64 编解码工具类
 * @author linling
 *
 */
public class Base64Utils
{

	private static Base64Utils base64Utils = new Base64Utils();
	private static Encoder base64Encoder;
	private static Decoder base64Decoder;

	private Base64Utils()
	{
		base64Encoder = Base64.getEncoder();
		base64Decoder = Base64.getDecoder();
	}

	public static Base64Utils getInstance()
	{
		return base64Utils;
	}

	/**
	 * base64 编码
	 * @param data
	 * @return
	 */
	public String encoder(byte[] data)
	{
		return base64Encoder.encodeToString(data);
	}

	/**
	 * base64 解码
	 * @param data
	 * @return
	 * @throws IOException
	 */
	public byte[] decoder(String data) throws IOException
	{
		return base64Decoder.decode(data);
	}

}
